package com.grape.testproducer.impl;

import cn.hutool.core.util.RandomUtil;
import com.grape.service.api.testproducer.ITestProducerService;
import com.grape.testproducer.TestProducer;
import com.grape.testproducer.User;
import com.grape.testproducer.impl.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述:生产者接口
 * @author: myx
 * @date: 2019-05-25
 * Copyright © 2019-grape. All rights reserved.
 */
@RestController
public class TestProducerSweviceImpl implements ITestProducerService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public TestProducer getTestProducer(String name) {
        return new TestProducer(RandomUtil.randomInt(),name);
    }

    @Override
    public List<User> getUserListByH2() {
        return userMapper.selectList(null);
    }

    @Override
    public int addUser(@RequestBody  User user) {
        return userMapper.insert(user);
    }

    @Override
    public int updateUser(@RequestBody User user) {
        return userMapper.updateById(user);
    }

    @Override
    public int deleteUser(Integer id) {
        return userMapper.deleteById(id);
    }


}
